import request from '@/utils/request'

const menuApi = {
    questionsApi: "/api/app/questions",
    questionTypeApi: "/api/app/questype"
}

class Service {
    /*
        获取全部试题
    */
    static getQuestions(){
        return request({
            url: menuApi.questionsApi,
            method: 'get',
            json: true,
        }).then((res) => {
            if (res.code === 200) {
                return Promise.resolve(res)
            }
            return Promise.reject(res)
        })
    }

    /*
        添加试题
    */
    static postQuestions(data){
        return request({
            url: menuApi.questionsApi,
            method: 'post',
            json: true,
            data
        }).then((res) => {
            if (res.code === 200) {
                return Promise.resolve(res)
            }
            return Promise.reject(res)
        })
    }

    /*
        修改试题
    */
    static putQuestions(data){
        return request({
            url: menuApi.questionsApi,
            method: 'put',
            json: true,
            data
        }).then((res) => {
            if (res.code === 200) {
                return Promise.resolve(res)
            }
            return Promise.reject(res)
        })
    }

    /*
        删除试题
    */
   static deleteQuestions(i){
       return request({
           url: `/api/app/questions?id=${i}`,
           method: 'delete',
           json: true,
       }).then((res) => {
           if (res.code === 200) {
               return Promise.resolve(res)
           }
           return Promise.reject(res)
       })
   }

    // 批量删除
    static deleQuestions(data){
        return request({
            url: `/api/app/questions`,
            method: 'delete',
            json: true,
            data
        }).then((res) => {
            if (res.code === 200) {
                return Promise.resolve(res)
            }
            return Promise.reject(res)
        })
    }

    // 添加题型
    static postQuestionType(data){
        console.log(data, "Aaaaaa")
        return request({
            url: menuApi.questionTypeApi,
            method: 'post',
            json: true,
            data
        }).then((res) => {
            if (res.code === 200) {
                return Promise.resolve(res)
            }
            return Promise.reject(res)
        })
    }

    // 获取题型
    static getQuestionType(){
        return request({
            url: menuApi.questionTypeApi,
            method: 'get',
            json: true,
        }).then((res) => {
            if (res.code === 200) {
                return Promise.resolve(res)
            }
            return Promise.reject(res)
        })
    }

    /*
        删除试题
    */
   static deleteQuestType(i){
        return request({
            url: `/api/app/questype?id=${i}`,
            method: 'delete',
            json: true,
        }).then((res) => {
            if (res.code === 200) {
                return Promise.resolve(res)
            }
            return Promise.reject(res)
        })
    }

    /*
        修改试题类型
    */
    static putQuestType(data){
        return request({
            url: menuApi.questionTypeApi,
            method: 'put',
            json: true,
            data
        }).then((res) => {
            if (res.code === 200) {
                return Promise.resolve(res)
            }
            return Promise.reject(res)
        })
    }

}


export default Service

